package EMS::Dispatcher;
use Jifty::Dispatcher -base;

use Jifty;

# Generic restrictions
#under '/', run {
#    Jifty->api->deny('ConfirmEmail');
#};

# this processing happens on every page that we hit, to try to figure out
# who the user is, where they came from, and how they're browsing us
under '/', run {
    # get the headers, put into a hashref with lowercased header names so we
    # can easily figure out what we need
    my %headers_in = Jifty->handler->apache->headers_in;
    $headers_in{lc $_} = delete $headers_in{$_} foreach keys %headers_in;

    # the idea is to do some work to figure out what kind of pages
    # to serve, using a prefix to define which elements to serve from
    my $prefix = '';

    # now examine the useragent
    my $ua = $headers_in{'user-agent'};
    if ($ua =~ /EVE-minibrowser/) {
        # they're coming in from the IGB, so set the prefix
        $prefix = 'igb-';

        # now do custom authentication against the headers to see who they
        # are claiming to be
        

    } else {
        # must be a regular visitor
        $prefix = 'web-';

        # see if they're logged in
    }
    
    # set parameters going into the page
    set prefix => $prefix;
};

# ensure the root shows /index
on '/', run {
    show('/index');
};

1;
